package com.xzh.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xzh.dao.StudentsMapper;
import com.xzh.model.Students;
import com.xzh.service.StudentsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class StudentsServiceImpl implements StudentsService {
    private StudentsMapper studentsMapper;
    @Autowired
    public void setStudentsMapper(StudentsMapper studentsMapper){
        this.studentsMapper = studentsMapper;
    }
    @Override
    public Page<Students> selectAll(Page<Students> page, Students students) {
        return studentsMapper.selectAll(page, students);
    }

    @Override
    public boolean save(Students students) {
        return studentsMapper.insert(students) > 0;
    }

    @Override
    public int removeByIds(List<Integer> ids) {
        return studentsMapper.deleteByIds(ids);
    }

    @Override
    public boolean updateById(Students students) {
        return studentsMapper.updateById(students) > 0;
    }

    @Cacheable(value = "studentStats", key = "'majorDistribution'")
    @Override
    public List<Map<String, Object>> statistics() {
        return studentsMapper.statistics();
    }

}
